2 Replies - 497 Views - Last Post: 21 February 2018 - 10:57 AM

#1 Balthazar   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 164
  • Joined: 16-November 15

JSF: Keeping text hidden until a button is pressed?

Posted 20 February 2018 - 04:59 PM

I didn't see a JSF forum, so hopefully I can post this here.

This week's homework is to write a JSF script that will allow a user to use a website to enter some information and it will calculate their taxes. This script is VERY basic, you just enter your yearly income and filing status and click Compute. The example picture shows the output in red below the Compute button. But this text doesn't show up *until* the button is pressed. This is the last piece I need to get working. I currently have the red text below the button with null/0 values that get filled in once the Calculate button is clicked.

I've been researching it, but I'm guessing I'm not using the right phrasing.

The line I currently have is:
<h:commandButton value="Compute Tax" action = "#{computeTaxBean.getResult()}"/> 


but I get an error with that. So I moved the GetResult call to the bottom and did:
<h:outputLabel escape="false" style="color:red" 
                   value="#{computeTaxBean.getResult()}"/>


but that's the part that just puts the red text on the screen from the beginning.
I have screen shots of these, but I keep getting an error when trying to attach them.

Any thoughts?

Is This A Good Question/Topic? 0
  • +

Replies To: JSF: Keeping text hidden until a button is pressed?

#2 ndc85430   User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,832
  • Joined: 13-June 14

Re: JSF: Keeping text hidden until a button is pressed?

Posted 20 February 2018 - 11:01 PM

I'd expect that you need to use Javascript to update the page when the button is pressed (i.e. some code that's run on the button's click event).
Was This Post Helpful? 0
  • +
  • -

#3 Balthazar   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 164
  • Joined: 16-November 15

Re: JSF: Keeping text hidden until a button is pressed?

Posted 21 February 2018 - 10:57 AM

Thanks, though it turns out there is a "rendered" property you can use. So I just set a boolean in my bean and then have the button press call the method that sets that bool to true, then the text displays.

index.xhtml
<!-- Use command button -->
            <h:commandButton value="Compute Tax" action = "#{computeTaxBean.setBoolResult()}"/>    
            <h:commandButton value="Reset" action ="#{computeTaxBean.reset}"/>

            <!--Only show result text once the Compute Tax button is clicked-->
            <h:outputText escape="false" style="color:red" value="#{computeTaxBean.result}" 
                                    rendered="#{computeTaxBean.boolResult}"/>


ComputeTaxBean.java
// Sets the boolean used for displaying results
    public void setBoolResult() {
        boolResult = true;
    }

    // Returns the boolean used for displaying results
    public boolean getBoolResult() {
        return boolResult;
    }


I tried just using the boolean itself, but for some reason it wouldn't work. It works as needed this way, and I haven't gotten any errors. Now I know that doesn't mean there *won't be* errors, but it should work for my homework.

This post has been edited by Balthazar: 21 February 2018 - 11:01 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1