Hi
Checking some tomahawk stuff I have noted that when I'm using trinidad (any
version 1.1 and 1.2) at the end of the form the hidden field that stores or
references the state:
<input type="hidden" name="javax.faces.ViewState"
never render its id="javax.faces.ViewState" as myfaces and jsf ri does.
the api javadoc of ResponseStateManager.isPostback says this:
*The implementation if this method for the Standard HTML RenderKit must
consult the ExternalContext<http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/context/ExternalContext.html>'s
requestParameterMap and return true if and only if there is a key equal to
the value of the symbolic constant
VIEW_STATE_PARAM<http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/render/ResponseStateManager.html#VIEW_STATE_PARAM>
.*
*For backwards compatability with implementations of
ResponseStateManagerprior to JSF 1.2, a default implementation is
provided that consults the
ExternalContext<http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/context/ExternalContext.html>'s
requestParameterMap and return true if its size is greater than 0.*
Trinidad implements its own ResponseStateManager like this:
public class CoreResponseStateManager extends ResponseStateManager
{
/* ......code ....*/
/**
* Write the state into the page.
* @todo Stream the resulting state into the page's content
* instead of buffering it.
* @todo Don't directly write out hidden input field; use an abstraction
*/
@Override
public void writeState(
FacesContext context,
StateManager.SerializedView serializedView) throws IOException
{
ResponseWriter rw = context.getResponseWriter();
rw.startElement("input", null);
rw.writeAttribute("type", "hidden", null);
rw.writeAttribute("name", VIEW_STATE_PARAM, null);
// Don't write out the ID, as it can be written
// out twice
rw.writeAttribute("id", VIEW_STATE_PARAM, null);
String s = encodeSerializedViewAsString(serializedView);
rw.writeAttribute("value", s, null);
rw.endElement("input");
}
@Override
/**
* A request is a postback if it contains the state parameter.
*/
public boolean isPostback(FacesContext context)
{
Map requestParams =
context.getExternalContext().getRequestParameterMap();
return requestParams.containsKey(VIEW_STATE_PARAM);
}
On trinidad 1.1 the commented code that render its id is missing.
The problem start when some code uses javax.faces.ViewState to find if the
request is a postback (trinidad has its own way to detect a postback using
another input field). If the id is missing, that code thinks that every
request is not a postback.
The commented code says that the id is duplicated, but checking code nothing
suggest that this is happening. I tried state saving client or server and no
problems were found.
I want to know if any developer has a reason to avoid render this id, and if
no objections I'll commit this change in 72 hours (doing this
s:inputSuggestAjax and s:tableSuggestAjax could work with trinidad and/or
facelets and solve TOMAHAWK-1157).
Suggestions are welcome
regards
Leonardo Uribe
Yeah, this is a complex issue. And trinidad doesn't do it right
either. Here is what I was going to do for Trinidad (in my copious
amounts of spare time). :)
Each Portlet would have a root element. When a form is submitted via
ppr, the view state for each "javax.faces.ViewState" under that root
element would be changed. As for servlet environments, if no root dom
element is set up (ie. when used in a non-portlet environment), then it
would just replace all the ViewStates under the document element.
Scott
Leonardo Uribe wrote:
> Hi
>
> myfaces portlet bridge + myfaces 1.2.3 using jetty and pluto (using
> the portlet archetype) render this as ViewState param:
>
> <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="ImubpcgkK/otI292kHnd8m............
>
> I ignore what happens when use multiple jsf portlets in the same page,
> or when the page is using multiple forms on the same page (normal
> submits should work on both environmets, but ajaxified components?).
>
> I will take a look in deep about this, at this point the idea of use a
> getElementsByName to send the view state in ajax calls is the most
> compatible to apply in tomahawk.
>
> regards
>
> Leonardo Uribe
>
>
> On Thu, Jun 12, 2008 at 10:20 AM, Mario Ivankovits <mario@ops.co.at
> <ma...@ops.co.at>> wrote:
>
> Hi!
>
> And also ensure that every ViewState will be replaced and
> not only the
> first [0] one.
> When you do have multiple JSF forms (which is valid) each
> ViewState
> needs to be replaced.
>
>
> Yes, but only when they came from the same view!
>
> I don't know much about JSF "portal bridge" stuff. Can this
> result in a
> page contains a form that was rendered via JSF from host A, and a
> different form that was rendered via JSF from host B?
>
> I'd say yes. You might be right.
> Don't know much about protlets either, but, I guess one solution
> can be to replace only those ViewState fields with the same value
> as the one associated with the form the component is embedded in.
>
> Lets speak code:
>
> var enclosingForm = findEnclosingForm(theComponent);
> var oldViewState = enclosingForm["ViewState"].value;
> for (form : forms)
> {
> if (form["ViewState"].value == oldViewState)
> {
> form["ViewState"].value = newViewState;
> }
> }
>
> Or do any portlet have its own namespace reflected into the
> element id?
> Then this could be checked too, though, this will be a portlet
> specific solution then.
>
> Ciao,
> Mario
>
>
On Fri, Jun 13, 2008 at 12:07 AM, Mario Ivankovits <ma...@ops.co.at> wrote: > Hi! > > I ignore what happens when use multiple jsf portlets in the same page, > > or when the page is using multiple forms on the same page (normal > > submits should work on both environmets, but ajaxified components?). > With "I ignore" you mean you will not replace the ViewState for each > form having a ViewState hidden field? > If so, this is bad I think, as having multiple forms is a perfect > possible scenario, subForm is not always the best answer. > With "I ignore" I want to say "I don't know". Sorry, my native language is spanish, so sometimes I translate wrong what I want to say ;). I agree with you, but I'm looking for which components should handle this scenario, because not every ajax enabled component should handle it (inputSuggestAjax and tableSuggestAjax for example). regards Leonardo Uribe > > Ciao, > Mario > >
Hi! > I ignore what happens when use multiple jsf portlets in the same page, > or when the page is using multiple forms on the same page (normal > submits should work on both environmets, but ajaxified components?). With "I ignore" you mean you will not replace the ViewState for each form having a ViewState hidden field? If so, this is bad I think, as having multiple forms is a perfect possible scenario, subForm is not always the best answer. Ciao, Mario
Hi
myfaces portlet bridge + myfaces 1.2.3 using jetty and pluto (using the
portlet archetype) render this as ViewState param:
<input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState" value="ImubpcgkK/otI292kHnd8m............
I ignore what happens when use multiple jsf portlets in the same page, or
when the page is using multiple forms on the same page (normal submits
should work on both environmets, but ajaxified components?).
I will take a look in deep about this, at this point the idea of use a
getElementsByName to send the view state in ajax calls is the most
compatible to apply in tomahawk.
regards
Leonardo Uribe
On Thu, Jun 12, 2008 at 10:20 AM, Mario Ivankovits <ma...@ops.co.at> wrote:
> Hi!
>
>> And also ensure that every ViewState will be replaced and not only the
>>> first [0] one.
>>> When you do have multiple JSF forms (which is valid) each ViewState
>>> needs to be replaced.
>>>
>>>
>> Yes, but only when they came from the same view!
>>
>> I don't know much about JSF "portal bridge" stuff. Can this result in a
>> page contains a form that was rendered via JSF from host A, and a
>> different form that was rendered via JSF from host B?
>>
> I'd say yes. You might be right.
> Don't know much about protlets either, but, I guess one solution can be to
> replace only those ViewState fields with the same value as the one
> associated with the form the component is embedded in.
>
> Lets speak code:
>
> var enclosingForm = findEnclosingForm(theComponent);
> var oldViewState = enclosingForm["ViewState"].value;
> for (form : forms)
> {
> if (form["ViewState"].value == oldViewState)
> {
> form["ViewState"].value = newViewState;
> }
> }
>
> Or do any portlet have its own namespace reflected into the element id?
> Then this could be checked too, though, this will be a portlet specific
> solution then.
>
> Ciao,
> Mario
>
>
Hi!
>> And also ensure that every ViewState will be replaced and not only the
>> first [0] one.
>> When you do have multiple JSF forms (which is valid) each ViewState
>> needs to be replaced.
>>
> Yes, but only when they came from the same view!
>
> I don't know much about JSF "portal bridge" stuff. Can this result in a
> page contains a form that was rendered via JSF from host A, and a
> different form that was rendered via JSF from host B?
I'd say yes. You might be right.
Don't know much about protlets either, but, I guess one solution can be
to replace only those ViewState fields with the same value as the one
associated with the form the component is embedded in.
Lets speak code:
var enclosingForm = findEnclosingForm(theComponent);
var oldViewState = enclosingForm["ViewState"].value;
for (form : forms)
{
if (form["ViewState"].value == oldViewState)
{
form["ViewState"].value = newViewState;
}
}
Or do any portlet have its own namespace reflected into the element id?
Then this could be checked too, though, this will be a portlet specific
solution then.
Ciao,
Mario
Mario Ivankovits schrieb: > Hi! > > >>> why not getElementsByName[0] ? >>> >> >> Well, in general document.getElementById is both faster and more >> elegant. >> >> So in this case, rendering this component with id=clientId seems >> reasonable. >> >> Hmm..but it is possible that there are multiple "view state" fields in >> the page, one per form. So perhaps using "getElementsByName" is a good >> idea in this specific case. >> > And also ensure that every ViewState will be replaced and not only the > first [0] one. > When you do have multiple JSF forms (which is valid) each ViewState > needs to be replaced. Yes, but only when they came from the same view! I don't know much about JSF "portal bridge" stuff. Can this result in a page contains a form that was rendered via JSF from host A, and a different form that was rendered via JSF from host B? If so, then a PPR response from host A should not update both forms.. Regards, Simon
Hi!
>> why not getElementsByName[0] ?
>>
>>
>
> Well, in general document.getElementById is both faster and more elegant.
>
> So in this case, rendering this component with id=clientId seems reasonable.
>
> Hmm..but it is possible that there are multiple "view state" fields in
> the page, one per form. So perhaps using "getElementsByName" is a good
> idea in this specific case.
>
And also ensure that every ViewState will be replaced and not only the
first [0] one.
When you do have multiple JSF forms (which is valid) each ViewState
needs to be replaced.
Ciao,
Mario
Matthias Wessendorf schrieb: > On Thu, Jun 12, 2008 at 7:02 AM, Leonardo Uribe <lu...@gmail.com> wrote: > >> On Thu, Jun 12, 2008 at 8:51 AM, simon.kitching@chello.at >> <si...@chello.at> wrote: >> >>> Leonardo Uribe schrieb: >>> >>>> >>>> On Wed, Jun 11, 2008 at 11:24 PM, Matthias Wessendorf >>>> <matzew@apache.org <ma...@apache.org>> wrote: >>>> >>>> > I want to know if any developer has a reason to avoid render >>>> this id, and if >>>> > no objections I'll commit this change in 72 hours (doing this >>>> > s:inputSuggestAjax and s:tableSuggestAjax could work with >>>> trinidad and/or >>>> > facelets and solve TOMAHAWK-1157). >>>> >>>> so, I guess I am not 100% getting your mail. >>>> why is the id needed ? >>>> >>>> >>>> For detect when a request is a postback using the procedure on the >>>> documentation. If is a postback the state is restored an the full >>>> lifecycle occur. If not a new view is created. >>>> >>>> Who detects postback in this way? the jsf implementation used! >>>> >>> I think Matthias meant that the html "name" attribute is all that is >>> significant for html. That is what gets used in creating the http post >>> data. The "id" attribute is only relevant for javascript and css. And >>> css certainly shouldn't be accessing this field. >>> > > yup > > >>> Do you want the id attribute set so that javascript associated with >>> AJAX-type controls can find this viewstate field? >>> > > why not getElementsByName[0] ? > Well, in general document.getElementById is both faster and more elegant. So in this case, rendering this component with id=clientId seems reasonable. Hmm..but it is possible that there are multiple "view state" fields in the page, one per form. So perhaps using "getElementsByName" is a good idea in this specific case. Question: in systems like portals, how does replacing the viewstate work? Presumably we would only want to replace the viewstate for those hidden inputs that really came from the same jsf view? Regards, Simon
On Thu, Jun 12, 2008 at 9:27 AM, Matthias Wessendorf <ma...@apache.org> wrote: > On Thu, Jun 12, 2008 at 7:02 AM, Leonardo Uribe <lu...@gmail.com> wrote: > > > > > > On Thu, Jun 12, 2008 at 8:51 AM, simon.kitching@chello.at > > <si...@chello.at> wrote: > >> > >> Leonardo Uribe schrieb: > >> > > >> > > >> > > >> > On Wed, Jun 11, 2008 at 11:24 PM, Matthias Wessendorf > >> > <matzew@apache.org <ma...@apache.org>> wrote: > >> > > >> > > I want to know if any developer has a reason to avoid render > >> > this id, and if > >> > > no objections I'll commit this change in 72 hours (doing this > >> > > s:inputSuggestAjax and s:tableSuggestAjax could work with > >> > trinidad and/or > >> > > facelets and solve TOMAHAWK-1157). > >> > > >> > so, I guess I am not 100% getting your mail. > >> > why is the id needed ? > >> > > >> > > >> > For detect when a request is a postback using the procedure on the > >> > documentation. If is a postback the state is restored an the full > >> > lifecycle occur. If not a new view is created. > >> > > >> > Who detects postback in this way? the jsf implementation used! > >> > >> I think Matthias meant that the html "name" attribute is all that is > >> significant for html. That is what gets used in creating the http post > >> data. The "id" attribute is only relevant for javascript and css. And > >> css certainly shouldn't be accessing this field. > > yup > > >> > >> Do you want the id attribute set so that javascript associated with > >> AJAX-type controls can find this viewstate field? > > why not getElementsByName[0] ? > > mmm, I will try it and see what happens. > > > > > Yes. The problem is when you use s:inputSuggestAjax and > s:tableSuggestAjax > > with trinidad. This components send a request for load the suggestions > and > > show it. If the id is not present, the viewstate is not found, so it is > not > > sent in the request (and not available on the request map), the state is > not > > restored and finally breaks tomahawk ajax api (and many dojo > components!). > > > >> > >> Regards, Simon > >> > > > > > > > > > > > > -- > Matthias Wessendorf > > further stuff: > blog: http://matthiaswessendorf.wordpress.com/ > sessions: http://www.slideshare.net/mwessendorf > mail: matzew-at-apache-dot-org >
On Thu, Jun 12, 2008 at 7:02 AM, Leonardo Uribe <lu...@gmail.com> wrote: > > > On Thu, Jun 12, 2008 at 8:51 AM, simon.kitching@chello.at > <si...@chello.at> wrote: >> >> Leonardo Uribe schrieb: >> > >> > >> > >> > On Wed, Jun 11, 2008 at 11:24 PM, Matthias Wessendorf >> > <matzew@apache.org <ma...@apache.org>> wrote: >> > >> > > I want to know if any developer has a reason to avoid render >> > this id, and if >> > > no objections I'll commit this change in 72 hours (doing this >> > > s:inputSuggestAjax and s:tableSuggestAjax could work with >> > trinidad and/or >> > > facelets and solve TOMAHAWK-1157). >> > >> > so, I guess I am not 100% getting your mail. >> > why is the id needed ? >> > >> > >> > For detect when a request is a postback using the procedure on the >> > documentation. If is a postback the state is restored an the full >> > lifecycle occur. If not a new view is created. >> > >> > Who detects postback in this way? the jsf implementation used! >> >> I think Matthias meant that the html "name" attribute is all that is >> significant for html. That is what gets used in creating the http post >> data. The "id" attribute is only relevant for javascript and css. And >> css certainly shouldn't be accessing this field. yup >> >> Do you want the id attribute set so that javascript associated with >> AJAX-type controls can find this viewstate field? why not getElementsByName[0] ? > > Yes. The problem is when you use s:inputSuggestAjax and s:tableSuggestAjax > with trinidad. This components send a request for load the suggestions and > show it. If the id is not present, the viewstate is not found, so it is not > sent in the request (and not available on the request map), the state is not > restored and finally breaks tomahawk ajax api (and many dojo components!). > >> >> Regards, Simon >> > > > > -- Matthias Wessendorf further stuff: blog: http://matthiaswessendorf.wordpress.com/ sessions: http://www.slideshare.net/mwessendorf mail: matzew-at-apache-dot-org
On Thu, Jun 12, 2008 at 8:51 AM, simon.kitching@chello.at < simon.kitching@chello.at> wrote: > Leonardo Uribe schrieb: > > > > > > > > On Wed, Jun 11, 2008 at 11:24 PM, Matthias Wessendorf > > <matzew@apache.org <ma...@apache.org>> wrote: > > > > > I want to know if any developer has a reason to avoid render > > this id, and if > > > no objections I'll commit this change in 72 hours (doing this > > > s:inputSuggestAjax and s:tableSuggestAjax could work with > > trinidad and/or > > > facelets and solve TOMAHAWK-1157). > > > > so, I guess I am not 100% getting your mail. > > why is the id needed ? > > > > > > For detect when a request is a postback using the procedure on the > > documentation. If is a postback the state is restored an the full > > lifecycle occur. If not a new view is created. > > > > Who detects postback in this way? the jsf implementation used! > > I think Matthias meant that the html "name" attribute is all that is > significant for html. That is what gets used in creating the http post > data. The "id" attribute is only relevant for javascript and css. And > css certainly shouldn't be accessing this field. > > Do you want the id attribute set so that javascript associated with > AJAX-type controls can find this viewstate field? > Yes. The problem is when you use s:inputSuggestAjax and s:tableSuggestAjax with trinidad. This components send a request for load the suggestions and show it. If the id is not present, the viewstate is not found, so it is not sent in the request (and not available on the request map), the state is not restored and finally breaks tomahawk ajax api (and many dojo components!). > > Regards, Simon > >
Leonardo Uribe schrieb: > > > > On Wed, Jun 11, 2008 at 11:24 PM, Matthias Wessendorf > <matzew@apache.org <ma...@apache.org>> wrote: > > > I want to know if any developer has a reason to avoid render > this id, and if > > no objections I'll commit this change in 72 hours (doing this > > s:inputSuggestAjax and s:tableSuggestAjax could work with > trinidad and/or > > facelets and solve TOMAHAWK-1157). > > so, I guess I am not 100% getting your mail. > why is the id needed ? > > > For detect when a request is a postback using the procedure on the > documentation. If is a postback the state is restored an the full > lifecycle occur. If not a new view is created. > > Who detects postback in this way? the jsf implementation used! I think Matthias meant that the html "name" attribute is all that is significant for html. That is what gets used in creating the http post data. The "id" attribute is only relevant for javascript and css. And css certainly shouldn't be accessing this field. Do you want the id attribute set so that javascript associated with AJAX-type controls can find this viewstate field? Regards, Simon
On Wed, Jun 11, 2008 at 11:24 PM, Matthias Wessendorf <ma...@apache.org> wrote: > > I want to know if any developer has a reason to avoid render this id, and > if > > no objections I'll commit this change in 72 hours (doing this > > s:inputSuggestAjax and s:tableSuggestAjax could work with trinidad and/or > > facelets and solve TOMAHAWK-1157). > > so, I guess I am not 100% getting your mail. > why is the id needed ? For detect when a request is a postback using the procedure on the documentation. If is a postback the state is restored an the full lifecycle occur. If not a new view is created. Who detects postback in this way? the jsf implementation used! regards Leonardo Uribe > -M > > > > > Suggestions are welcome > > > > regards > > > > Leonardo Uribe > > > > > > > > > > -- > Matthias Wessendorf > > further stuff: > blog: http://matthiaswessendorf.wordpress.com/ > sessions: http://www.slideshare.net/mwessendorf > mail: matzew-at-apache-dot-org >
> I want to know if any developer has a reason to avoid render this id, and if > no objections I'll commit this change in 72 hours (doing this > s:inputSuggestAjax and s:tableSuggestAjax could work with trinidad and/or > facelets and solve TOMAHAWK-1157). so, I guess I am not 100% getting your mail. why is the id needed ? -M > > Suggestions are welcome > > regards > > Leonardo Uribe > > > -- Matthias Wessendorf further stuff: blog: http://matthiaswessendorf.wordpress.com/ sessions: http://www.slideshare.net/mwessendorf mail: matzew-at-apache-dot-org
I made a mistake copy paste the code of writeState. Actually looks like
this:
public void writeState(
FacesContext context,
StateManager.SerializedView serializedView) throws IOException
{
ResponseWriter rw = context.getResponseWriter();
rw.startElement("input", null);
rw.writeAttribute("type", "hidden", null);
rw.writeAttribute("name", VIEW_STATE_PARAM, null);
// Don't write out the ID, as it can be written
// out twice
// rw.writeAttribute("id", VIEW_STATE_PARAM, null);
String s = encodeSerializedViewAsString(serializedView);
rw.writeAttribute("value", s, null);
rw.endElement("input");
}
regards
Leonardo Uribe
On Wed, Jun 11, 2008 at 10:12 PM, Leonardo Uribe <lu...@gmail.com> wrote:
> Hi
>
> Checking some tomahawk stuff I have noted that when I'm using trinidad (any
> version 1.1 and 1.2) at the end of the form the hidden field that stores or
> references the state:
>
> <input type="hidden" name="javax.faces.ViewState"
>
> never render its id="javax.faces.ViewState" as myfaces and jsf ri does.
>
> the api javadoc of ResponseStateManager.isPostback says this:
>
> *The implementation if this method for the Standard HTML RenderKit must
> consult the ExternalContext<http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/context/ExternalContext.html>'s
> requestParameterMap and return true if and only if there is a key equal to
> the value of the symbolic constant VIEW_STATE_PARAM<http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/render/ResponseStateManager.html#VIEW_STATE_PARAM>
> .*
>
> *For backwards compatability with implementations of ResponseStateManagerprior to JSF 1.2, a default implementation is provided that consults the
> ExternalContext<http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/context/ExternalContext.html>'s
> requestParameterMap and return true if its size is greater than 0.*
>
> Trinidad implements its own ResponseStateManager like this:
>
> public class CoreResponseStateManager extends ResponseStateManager
> {
>
> /* ......code ....*/
> /**
> * Write the state into the page.
> * @todo Stream the resulting state into the page's content
> * instead of buffering it.
> * @todo Don't directly write out hidden input field; use an abstraction
> */
> @Override
> public void writeState(
> FacesContext context,
> StateManager.SerializedView serializedView) throws IOException
> {
> ResponseWriter rw = context.getResponseWriter();
> rw.startElement("input", null);
> rw.writeAttribute("type", "hidden", null);
> rw.writeAttribute("name", VIEW_STATE_PARAM, null);
> // Don't write out the ID, as it can be written
> // out twice
> rw.writeAttribute("id", VIEW_STATE_PARAM, null);
>
> String s = encodeSerializedViewAsString(serializedView);
> rw.writeAttribute("value", s, null);
>
> rw.endElement("input");
> }
>
> @Override
> /**
> * A request is a postback if it contains the state parameter.
> */
> public boolean isPostback(FacesContext context)
> {
> Map requestParams =
> context.getExternalContext().getRequestParameterMap();
> return requestParams.containsKey(VIEW_STATE_PARAM);
> }
>
> On trinidad 1.1 the commented code that render its id is missing.
>
> The problem start when some code uses javax.faces.ViewState to find if the
> request is a postback (trinidad has its own way to detect a postback using
> another input field). If the id is missing, that code thinks that every
> request is not a postback.
>
> The commented code says that the id is duplicated, but checking code
> nothing suggest that this is happening. I tried state saving client or
> server and no problems were found.
>
> I want to know if any developer has a reason to avoid render this id, and
> if no objections I'll commit this change in 72 hours (doing this
> s:inputSuggestAjax and s:tableSuggestAjax could work with trinidad and/or
> facelets and solve TOMAHAWK-1157).
>
> Suggestions are welcome
>
> regards
>
> Leonardo Uribe
>
>
>