how do I pass outputtext to other form - jsf

as simple as this. But the outputtext is not passed to another function or form. inputtext of course works but looks ugly.
What should I subsititute outputtext with?
<h:form>
<h:outputtext value="xx" />
<h:commandButton action="#{serviceTest.function() }" value="test"
</h:commandButton>
</h:form>
Real world example
<p:column id="average" sortBy="#{resultClub.stringAverage}">
<f:facet name="header">Snitt</f:facet>
<h:outputText id="testing" value="#{resultClub.stringAverage}" />
<h:inputHidden id="hiddenAvg" value="#{resultClub.stringAverage}" />
</p:column>
javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /hcp/showAverages.xhtml #96,74 value="#{resultClub.stringAverage}": Property 'stringAverage' not writable on type com.jk.hcp.ResultClub
javax.faces.component.UIInput.updateModel(UIInput.java:867)
javax.faces.component.UIInput.processUpdates(UIInput.java:749)
org.primefaces.component.api.UIData.process(UIData.java:328)

After you described the problem to me, I figure it out for you...
You can do this by using javascript
Outputtext:
<h:outputText id="text1" value="xx" />
Button:
<h:commandButton value="click me"
action="#{serviceTest.function()}" value="test"
onclick="submitFieldValue()" >
</h:commandButton>
XHTML:
This will set the myfield instance variable in your controller. It basically will generate a java script function at compile time which will be able to call the controller.
<a4j:jsFunction name="setTheValue">
<a4j:actionparam name="param" assignTo="#{serviceTest.myfield}"/>
</a4j:jsFunction>
JavaScript:
This will call setTheValue with the outputtext value
function submitFieldValue(){
var x = document.getElementById("text1").value;
setTheValue(x);
}

If you want to have the "xx" value submitted after clicking on the commandButton, you can either use hidden field for it
<h:inputHidden value="some text" />
or you can use
<h:inputText readonly="true" />
which will render the text in an input text that user cannot change (it may look like the outputText), but its value will be submitted after clicking the button.

What I understand is that you want to view some data in the outputtext after the button is pressed, right?
Please if I got it wrong, tell me to delete the answer!
Is this case you need to make the button renders the outputfield upon clicked:
Outputtext:
<h:outputText id="text1" value="#{serviceTest.text1Value}" />
Button:
<a4j:commandButton value="click me"
action="#{serviceTest.function() }" value="test"
render="text1" >
</a4j:commandButton>
As you can see I used a4j:commandButton which will enable me to render any element on the page by id upon click.

Related

InputText not working with when using length() function With Flash object?

When page rendered first time textbox was empty and when i click a button and called a action and update the value like this it worked and textbox updated with new value
Flash flash = FacesContext.getCurrentInstance().getExternalContext()
.getFlash();
flash.put("errorMessage",featuesObj.getName() + "Some Error came");
<h:inputText value="#{flash.errorMessage }" id="mymessage" />
But now made a little changes in textbox and added a rendered now text box not displayed even pressing command button while #{flash.errorMessage} already have some String value
<h:inputText value="#{flash.errorMessage}" rendered="#{flash.errorMessage.length() gt 0 }" id="mymessage" />
Even i tried below code as well
<h:inputText value="#{flash.errorMessage.length()}" id="mymessage" />
Its always showing false in textbox even i press the button.
Can someone please let me know what can be issue?
This is the answer of my problem
Ajax rendering of content which is by itself conditionally rendered
Ajax rendering takes place fully at the client side and expects the to-be-updated HTML element to be already in the JSF-generated HTML output.
Following will not work when #{bean.renderResult} defaults to false:
<h:form id="form">
<h:commandButton value="Submit" action="#{bean.toggleRenderResult}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:outputText id="result" value="#{bean.result}" rendered="#{bean.renderResult}" />
You need to ensure that the render ID points to a component which is already present in the JSF-generated HTML output.
Following will work:
<h:form id="form">
<h:commandButton value="Submit" action="#{bean.toggleRenderResult}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:panelGroup id="result">
<h:outputText value="#{bean.result}" rendered="#{bean.renderResult}" />
</h:panelGroup>
http://balusc.blogspot.in/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichIsByItselfConditionallyRendered

ViewState updated/changed when part of page rendered

My code looks like this:
<h:panelGroup id="panelA" >
<h:panelGroup id="panelB" rendered="#{!bean.editEnabled}">
<h:outputText value="#{bean.valueA}" styleClass="readOnlyBox wide hasButton" />
<a4j:commandLink title="edit" action="#{bean.setEditingModeToTrue}"
styleClass="icon edit" render="panelA">
</a4j:commandLink>
</h:panelGroup>
<h:panelGroup id="panelC" rendered="#{bean.editEnabled}">
<h:inputText value="#{bean.valueA}" styleClass="input wide" validatorMessage="Error">
<f:validateLength maximum="80"/>
<f:validateRegex pattern=".*\\<[^>]+>.*"/>
</h:inputText>
<a4j:commandLink title="save" action="#{bean.doValueSave}"
styleClass="icon save" render="panelA">
</a4j:commandLink>
</h:panelGroup>
</h:panelGroup>
Problem occurs when I click on link save. Then linked method is not called. Bean has a view scope and I guess that when I click on edit button (that is required in order to make field editable) then view state is lost so that when I click on save button nothing happends. Am I right? Is there any workaround for this problem? Bean must to have view scope... :/

Dynamic navigation with parameter passing in JSF

I want to pass the "title" parameter in the following listing dynamicaly to another jsf Facelet, depending on the selection of the selectOneMenu. My first approach looks like this:
<h:form id="form">
<p:selectOneMenu value="#{exerciseEditorBean.selectedExerciseType}" >
<f:selectItem itemLabel="Multiple Choice Exercise" itemValue="MultipleChoiceExercise" />
<f:selectItem itemLabel="Vocabulary Test" itemValue="VocabularyTest" />
</p:selectOneMenu>
<h:outputText value="Enter Title of your Exercise: " />
<h:inputText id="title" value="#{exerciseEditorBean.exerciseTitle}" />
<h:commandButton value="Next" action="#{exerciseEditorBean.openEditor()}" />
</h:form>
The ExerciseEditorBean is ViewScoped.
The openEditor() function then decides by the selectedExerciseType attribute which Facelet to show next and returns something like "multipleChoiceEditor.xhtml".
How can I now pass the titel attribute to this Facelet?
I now use the f:ViewParam in the target servelet, which works well except, that "multipleChoiceEditor.xhtml?includeViewParams=true" does not work, but this is another issue. Thanks for the discussion!

Submit popup panel content, rich:popupPanel

I am trying to submit values in a pop-up panel inside another panel that has a submit/action event. But before opening pop-up panel I need to invoke a function on my managed bean that create a new entity object. The outer panel has the only h:form, since you can't nest them. I have wrapped the pop-up panel in a a4j:region to submit only this part when the use submits the values inside the pop-up panel. This works, but not the execution of the preparing function that need to be invoked when the pop-up panel executes. I have tried a4j:commandLink but that component don't work together with the rich:popupPanel (strange since both of them are Richfaces components?!). So I have to relay on the h:commandLink and use ajax.
How can I invoke a function on my managed bean when the link to open/render the pop-up panel fires?
(What is the correct pattern for this?)
PS. The initial question has changed, but not the problem concerning submitting values in a pop-up panel.
Part of the xhtml file:
<h.form>
...
<a4j:region>
<rich:popupPanel id="popup_sys_user_req" modal="false" autosized="true" resizeable="false">
<f:facet name="header">
<h:outputText value="Request New Sector/Category" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#"
onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<h:panelGrid columns="2">
<h:outputLabel value="Request New:" />
<h:selectOneMenu id="sys_req_type" value="#{userController.selectedSysUserRequest.sysrequesttype}" required="true" >
<f:selectItems value="#{userController.getSysRequestTypeItems('SECTOR_CATEGORY')}">
</f:selectItems>
</h:selectOneMenu>
<h:outputLabel value="Description:" />
<h:inputTextarea id="user_req_desc" value="#{userController.selectedSysUserRequest.description(desc)}" required="true" requiredMessage="Decription is missing" />
</h:panelGrid>
<a4j:commandButton action="#{userController.CreateSysUserRequest()}" value="Send Request" execute="sys_user_req_form" oncomplete="#{rich:component('popup_sys_user_req')}.hide(); return false;"/>
</rich:popupPanel>
</a4j:region>
</h:form>
The commandLink (re-edit)
<h:commandLink actionListener="#{userController.prepareCreateSysRequest}" value="Request New Sector/Category">
<f:ajax execute="popup_sys_user_req #this" render="popup_sys_user_req">
<rich:componentControl id="popup_ctr" event="click" target="popup_sys_user_req" operation="show"/>
</f:ajax>
</h:commandLink>
----------------------------
//Managed Bean:
public void prepareCreateSysRequest(ActionEvent event ) {
selectedSysUserRequest = new Sysuserrequest();
JsfUtil.log("Prepare Create System User Request");
}
This post continues the dicussion about the pop-up panel.
Greetings Chris.
If I understand correctly you want to submit all form elements inside popupPanel but not outside the panel when you invoke someAction1? I can think of two ways to do this:
1. a4jcommandButton has a limitToList attribute, you can list which components you want to be updated on the server
2. create your popupPanel outside of the first form and then use its own form:
<h:form>
...
<a4j:commandButton action="someAction2"...
</h:form>
<rich:popupPanel>
<h:form>
...
<a4j:commandButton action="someAction1"...
</h:form>
</rich:popupPanel>
Update
If you are using RichFaces 4 you can replace the limitToList attribute with limitRender
The problem is that the popup isn't a child of the form in jsf, you only need to use the domElementAttachment attribute to change that. So your code would look like this:
<h.form>
...
<a4j:region>
<rich:popupPanel id="popup_sys_user_req" modal="false" autosized="true" resizeable="false" domElementAttachment="form">
<f:facet name="header">
...

a4j rerender inputText onSubmit event

I tried different combinations to just rerender the result pannel.
it works fine with
<h:form><a4j:region>
<h:inputText value="#{myBean.keyword}">
<a4j:support event="onchange" reRender="results" eventsQueue="search" oncomplete="initResults();" />
</h:inputText>
</a4j:region>
</h:form>
But i just want to submit it when enter is pressed. So i tried
<h:form reRender="results" eventsQueue="search" oncomplete="initResults();"><a4j:region>
<h:inputText value="#{myBean.keyword}"/>
</a4j:region>
</h:form>
that returned an empty result even if it shouldn't be empty and
<a4j:region>
<h:form>
<a4j:support event="onsubmit" reRender="results" eventsQueue="search" oncomplete="initResults();" />
<h:inputText value="#{myBean.keyword}"/>
</h:form>
</a4j:region>
was reloading the whole page and not the result panel only (but results where shown). I even tried to add <h:form onSubmit="return false;"> in the last example. [EDIT: ok that return false is just overwritten by the AJAX support call]
How do i make my inputText field rerender when "enter" is pressed. (so the form is submitted) but don't want to submit the form.
EDIT: again my bad, i simplified the example code here too much. i had a second element with a4j:support in the same form, since i removed the a4j tag there and changed the onchange event to a form submit, too, it is working.
<h:selectOneMenu value="#{myBean.selectedMetaCategory}" onchange="this.form.submit();">
<a4j:support ...
<f:selectItems value="#{myBean.metaSelectItems}"/>
</h:selectOneMenu>
Try like this:
<a4j:region>
<a4j:form onsubmit="reRenderResults();">
<h:inputText value="#{myBean.keyword}"/>
</a4j:form>
<a4j:jsFunction name="reRenderResults" reRender="results" eventsQueue="search" oncomplete="initResults();" />
</a4j:region>

Resources