In JSF 1.1, is it possible to use value of inputText as f:parm of an outputLink?
For example:
<h:inputText value="enter Input Value" />
<h:outputLink value="someLink.jsp" styleClass="searchButton">
<f:param name="userName" value="whatever the input value is" />
</h:outputLink>
Not with standard JSF. You'd need to bring in some JavaScript code.
E.g.
<h:form id="formId">
<h:inputText id="inputId" />
<h:outputLink value="someLink.jsp?userName=" onclick="href+=encodeURIComponent(document.getElementById('formId:inputId').value)" />
</h:form>
An alternative is to just use a plain vanilla HTML.
<f:verbatim>
<form action="someLink.jsp">
<input type="text" name="userName" />
<input type="submit" />
</form>
</f:verbatim>
You could if necessary add some CSS to make the button to look like a link.
Related
I have such code as follow in my input.xhtml file which takes input from user. But this BootsFaces code is not working, Please Someone help me to solve this problem if any one faced it Before.
<b:form id="studentForm" styleClass="form-horizontal">
<h:panelGrid columns="1" cellpadding="5">
<b:inputText label="E-mail:" labelStyle="width:80px;">
<f:facet name="prepend">
<h:inputText value="#{studentBean.firstName}" styleClass="form-control" />
</f:facet>
</b:inputText>
</h:panelGrid>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<b:commandButton value="Create" action="#{studentBean.createStudentForm}" styleClass="btn btn-default" />
</div>
</div>
</b:form>
You are using the b:inputText incorrectly. You should not wrap a h:inputText in it. You can bind the value using the b:inputText tag:
<b:inputText label="First name:"
labelStyle="width:80px;"
value="#{studentBean.firstName}"/>
See also:
https://showcase.bootsfaces.net/forms/inputText.jsf (documentation).
https://github.com/TheCoder4eu/BootsFacesWeb (if you want to download the showcase and its examples).
I want to create JSF form with attached file. But also to give a option form the users to submit the for without attach file. I don't want this to be mandatory.
<h:form id="form" enctype="multipart/form-data">
<div class="string">
<label class="name">
<h:inputText id="name" value="#{contacts.name}" pt:placeholder="Name*:"/>
</label>
</div>
<label class="message">
<h:inputTextarea value="#{contacts.comment}" pt:placeholder="Comment*:"/>
</label>
<h:inputFile id="fileToUpload" value="#{contacts.file}" required="true" requiredMessage="No file selected ..."/>
<h:commandButton value="Upload" action="#{contacts.upload()}">
<f:ajax execute="fileToUpload" />
</h:commandButton>
<h:message showDetail="false" showSummary="true" for="fileToUpload" style="color:red"/>
<div class="btns">
<h:commandLink id="submitlink" class="link" value="submit" action="#{contacts.sendEmail}" >
<f:ajax render="#form" execute="#form" onevent="handleDisableButton" resetValues="true"/>
</h:commandLink>
</div>
<h:outputText id="output" value="#{contacts.result}" />
</h:form>
Is there a way to implement this because now if I try to submit the form I always get message No file selected ...?
Also when I attach a file using the button upload button no message appears for successful file upload.
You have your inputFile as required. That is why you have to upload first always.
Also, if you are not seeing any message it's because you are not rendering again your h:message. Try using this in your managed bean:
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds()
.add("idMessage");
change
<h:inputFile id="fileToUpload" value="#{contacts.file}" required="true" requiredMessage="No file selected ..."/>
to
<h:inputFile id="fileToUpload" value="#{contacts.file}" />
hi as per my requirement there is one h:inputtext to find user. If user is found it populated first name, last name and email in corresponding h:inputtext which is disabled. but if not found that inputtext should become enabled and new details can be filled.
<h:inputText value="#{countryBean.usersDetailsDTO.eid}" id="eid" required="true" requiredMessage="Enter EID">
<f:ajax></f:ajax>
</h:inputText><h:message styleClass="msgStyle4" id="msgEid" for="eid"/>
</div>
<h:commandButton styleClass="search_btn" immediate="true">
<f:ajax listener="#{countryBean.getUserDetail}" render="empFName empLName empEmail" event="click" execute="#this" />
</h:commandButton>
<div class="clear"> </div>
<div class="form-field" style="margin-left:222px;">
first Name <h:inputText value="#{countryBean.usersDetailsDTO.firstName}" id="empFName" required="true" requiredMessage="Enter First Name">
<f:validator validatorId="nameValidation" />
</h:inputText><h:message styleClass="msgStyle4" id="msgfn" for="empFName"/>
</div>
<div class="clear"></div>
<div class="form-field" style="margin-left:10px;">
last name <h:inputText value="#{countryBean.usersDetailsDTO.lastName}" id="empLName" required="true" requiredMessage="Enter Last Name">
<f:validator validatorId="nameValidation" />
</h:inputText><h:message styleClass="msgStyle4" id="msgln" for="empLName"/>
</div><div class="clear"></div>
<div class="form-field" style="margin-left:10px;">
email<h:inputText value="#{countryBean.usersDetailsDTO.email}" id="empEmail" required="true" requiredMessage="Enter Email Address">
<f:validator validatorId="emailValidation" />
</h:inputText><h:message styleClass="msgStyle4" id="msgEmail" for="empEmail"/>
</div>
You can use disabled attribute on any time along with JSF EL to pass the Boolean value to disabled attribute.
For example in your case If you want to disable any h:inputText if first name is pre-populated then:
<h:inputText value="#{countryBean.usersDetailsDTO.email}" id="empEmail"
required="true" requiredMessage="Enter Email Address"
disabled="#{not(empty countryBean.usersDetailsDTO.firstName)}">
The above code will disable the Email input text disabled if firstname is pre-populated.
You can handle this on 2 ways:
1) You set the disable-tag of the inputText to a BackingBean-method like this:
<h:inputText ... disabled="#{countryBean.found}" ... />
2) Adding a valueChangeListener on the first inputText, so if it has a text, the others should be disabled.
I have below code:
<h:commandLink action="#{clController.action()}"
value="#{item.code}" >
<input type="hidden" name="address" value="#{item.address}" />
<input type="hidden" name="address" value="#{item.name}" />
<input type="hidden" name="address" value="#{item.taxDept}" />
</h:commandLink>
Page lists more than 12 links like above. What i want to do sending all these hiddens to another jsf whichever user clicks.
When I click commandLink it goes other page. But How can I show these values?
You can't use <input /> directly in JSF.
Your inputs have all the same name.
In JSF, values posted are the one inside the same <h:form /> as the action (if not specified).
You can use something simple as a parameter :
<h:commandLink action="start" actionListener="#{clController.actionListener}">
<f:attribute name="item" value="#{item}" />
</h:commandLink>
public void actionListener(ActionEvent event)
{
ClDataModel item = (ClDataModel)event.getComponent().getAttributes().get("item");
System.out.print(item.getTaxDept());
System.out.print(item.getAddress());
System.out.print(item.getName());
}
I would like to implement a search box in my web-app. A JSF <h:form> should redirect me to products.xhtml?search=somestring. It should work the same as the following piece of HTML:
<form action="products.xhtml" method="GET">
<input type="text" name="search" />
<input type="submit" value="Submit" />
</form>
All the solutions of similar problems I came across does the redirection to another page without querystring
<h:form>
<h:inputText value="#{product.searchString}"/>
<h:commandButton value="Submit" action="products?faces-redirect=true&includeViewParams=true"/>
</h:form>
.
<h:form>
<h:inputText valueChangeListener="#{product.searchStringChanged}" />
<h:link value="Submit" outcome="products">
<f:param name="search" value="#{product.searchString}" />
</h:link>
</h:form>
OR builds the querystring but redirects to the same page.
The reason of not using pure HTML is to keep the benefits of the JSF session management.
EDIT
With the help of BalusC's post and https://blogs.oracle.com/enterprisetechtips/entry/post_redirect_get_and_jsf, I came up with following solution:
<f:metadata>
<f:viewParam name="search" value="#{product.search}" />
</f:metadata>
<h:form>
<h:inputText value="${product.search}"/>
<h:commandLink action="products?faces-redirect=true&includeViewParams=true" value="Search"/>
</h:form>