aspose file tools*
The moose likes JSF and the fly likes Templates cause my filter to stop working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Templates cause my filter to stop working" Watch "Templates cause my filter to stop working" New topic
Author

Templates cause my filter to stop working

Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
So... I really can't understand this one.

I had my pages all codded with the same .xhtml headers so I made a template to encase the same header properties and configurations and make my xhtml codding cleaner:



The name of my template is "temp1.xhtml" btw.

So now pages like this:



Causes this filter:



To cause the following error:



And I really can't put my thinger on what is causing such error... the pages worked fine without the template usage but, at least for me, my code seems correct!

What is causing such error? What could I do to solve it?

Note:

line 92 on the error report is, on the post, line 75. The error is somehow related to the action chain.doFilter(request, response) and, when I submit this application to my server, the error happens in another line, but with the same chain.doFilter(request, response) action.
Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
Another interesting fact:

This page works just fine and uses the same template as all the others



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

It isn't your filter that's failing, it's the View Definition (xhtml) compiler. To be precise, the xerces XML processor is saying that the View definition is improperly-formed XML.

You don't have an XML lead-in processing instruction such as "<?xml version="1.0" encoding="UTF-8"?>", and you are attempting to use both a DOCTYPE and XML schemas at the same time.

On top of that, a View Template Language "xhtml" file is not the same thing as the xhtml HTML specification.

So remove the XHTML DOCTYPE and add an XML header. Which must not be preceeded by spaces or blank lines.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
Hum... I tinkered around and got the template issue completely solved!

However now something that used to work doesn't do so anymore... what makes me feel even more stupid in this situation is that I have the exactle same structure in another page wich works...

The new problem is:

there's a button inside a dataTable wich deletes an specific entry in a List of objects by calling ".remove(Object);" in a method of the ManagedBean called BuscaMB:




the page in which it is called is this:



And whenever I click any method which uses the resultado List Object gets it wiped out, like if the object got reinstantiated in by some reason... I even put that button "teste" to see on the log if it was just a problem with showing data but it really had size 0...

And what most puzzles me is that there's another page wich work in the same way and works correctly!






It works on the same way! Why the first page won't work correctly anymore?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

Actually, if you have a different question, we would prefer that you start a new message thread. It will confuse people less.

You are not using either action methods nor the dataTable correctly.

Although JSF2 permits you to bind a collection or array directly to a dataTable, this ability has serious limitations. As a rule, except in display-only tables, you are recommended to construct a DataModel object in your backing bean, wrap your actual list within that (List)DataModel, and expose the dataModel as a property referenced by the "value=" attribute of the dataTable element.

The DataModel maintains a cursor, which is accessible to the action methods in order for them to know which row you clicked in. The "action=" attribute in the commandButton (or commandLink) should NOT contain a parameter. It is NOT a function call, it is a reference to an action method. There is no need for parameters, since all necessary information is already available from JSF or the backing bean. The action method should be returning a navigation string unless you want the current page to re-display.

Thus:


Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
Sorry for asking for another issue on the same post, after I wrap this up I'll do it again XD

So... I've made some changes, but the method still isn't being called by the the application... it still simply ignores the request...
I'm probably making something wrong still, Maybe I didn't got the DadaModel right yet, so far these are my modifications:



I'm still calling them the same way on the xhtml :



Where resultado is now a DataModel.

I would also like to note that the syntax wich I used (the ugly ((List<Noticia>)resultado.getWrappedData())) is just to express that I haven't been able to explicit convert the
Object output from .getWrappedData() to List<Noticia> without using the @SuppressWarnings("unchecked"), wich seem like a very bad idea to have around...

Any tips on that and why the method isn't being called?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21



Is improper. The action EL should be a reference, not an explicit function call. JSF will do the calling, just as JSF will update the backing bean properties when the action is fired.

The proper syntax is:


You don't need to re-wrap the List just because it has been updated. Once set, the wrapped data remains attached to the DataModel, and updating a List does not replace the List object itself, it only changes what data is in the list.

You also generally shouldn't be locating Session objects by brute force using the FacesContext, since the Inversion of Control paradigm that underlies JSF is based on the idea that you should be injecting them as Managed Properties.

When an action method isn't invoked, it's because either:

A) One or more form control values is invalid (assuming you are not using "immediate" operation)
B) The bean/action method reference name is miscoded (or miscapitalized)
C) The method signature for the action method is invalid.

I suspect that C) is at fault. Change removeNoticia to return a String, then make it return null. Returning void may not be proper here.
Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
Well, I've managed to discover wich element of my page was causing the problem!



The outputLink won't even apear on the page without the () on fazExtracao, it says that it's not an element from BuscaMB, even though that:




Without it the code works correctly :(

And it really has to be a outputLink in order to call my DownloadServlet (the one we talked about in here )

any advice?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

The onkeypress attribute is expected to refer to JavaScript code. Even if your method worked, the returned "javascript expression" would be something like "/baixar", which isn't legal javaScript.

Beyond that, your "get" method probably doesn't resolve due to method signature issues. "get" methods shouldn't be throwing checked Exceptions, I don't think.
Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
I did it! I know this isn't exactly right but is a solution to my issue:

I made the following xhtml code on the page:



This way the method is called, the outputLink calls the JS function and the file is prepared to download with the call of the commandButton "prepFile", which calls the DownloadServlet!

UPDATE: Actually the js is not right, it's not "pressing" the button... I'm searching the correct syntax...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

I'm totally confused. The "onkeypress" javascript event handler is not supposed to return a value, so the "/baixan" string is presumably simply being ignored. What you really seem to have coded is a hyperlink which, when clicked on, fires the command button instead of the link (image). You could have done that without any javascript just by using the <h:commandLink /> element instead out the outputLink element.

In answer to an earlier question, JavaScript and the View-side variables are all on the client (browser). JSF is all on the server. The only way to get JavaScript and JSF to communicate with each other is to use AJAX.
Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
Well... I still don't really understand how the eventTriggers behave... but this is my method with earlier returned "/baixar":



the only thing that is calling the DownloadServlet is really what the js is returning... and, well, the js isn't even calling the commandButton correctly (still have to figure out how to do so), it really must be it.

Rafael Campos Cruz
Ranch Hand

Joined: Apr 16, 2013
Posts: 39
Hum, now I uderstand.

What is calling the DownloadServlet is the " value='baixar' " on the outputLink... the JS isn't even being called I believe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Templates cause my filter to stop working