JSF component renderer - java

I'v build a JSF component which works fine, I can see that it's being rendered the way i want.
I have problem when open a pop up from the page.
when I return from the pop up I can in the component renderer that the attributes of the component are null. and so the html DOM element are not it was before I opened the popup.
when I reload the page the attributes gets their values.and the html DOM element back to normal.
Anyone know why ?
<MyComponent attr1="test1" attr2="test2">
</MyComponen>

I solve the problem after overriede saveState and restoreState methods of UIComponentBase
in my component.

Related

Vaadin: How to navigate without reloading the page?

I have to navigate between my components and I use a custom button like this:
button.addClickListener(click -> {
UI.getCurrent().navigate(ClassToNavigate.class);
});
The url does refresh in the search bar but it only shows a black page, I've to hit F5 to see the component in my parent layout.
My only fix is to add:
UI.getCurrent().getPage().reload();
...which reloads the page after navigating to the URL, and that breaks the UX in my opinion, however... when using a BeforeEnterEvent on a class and using the method:
forwardTo(ClassToNavigate.class);
redirects perfectly... although I can't have BeforeEnterEvent for every menu button I have, I can't see why forwardTo() works perfectly and navigate() doesn't.
Is there a way to navigate without having to reload the page? And without using RouterLink which I can't because I'm already using a custom component.
Thanks in advance!

How set content frame using htmlunit

I need to set the content HTML within an iframe, as pictured.
1- Below, I get the frame. But the frame does not have a setContent
FrameWindow frame = page.getFrames().get(0);
2- So I got BaseFrameElement. But, how to put html code in content?
BaseFrameElement frame = page.getFrames().get(0).getFrameElement();
frame.setTextContent(textContent);
If you have a better solution, let me know.
Thank you.
Not sure that i understand your problem. Usually some action on the page modifies the content of the iframe - there is no need to do this from the 'outside'.
Try something like
BaseFrameElement base = page.getFrames().get(0);
base.getEnclosedWindow().setEnclosedPage(newPage);
Keep in mind that this will not trigger all the events and might not have the result you expect.

Wicket implementation of bootstrap-wysiwyg

Im trying to figure out how to create a wicket component wicket could represent a div that is then used by the Bootstrap-wyiswyg javascript. Once the page is submitted i want to be able to get the content of the div and have that represented on the server, in a IModel<String>.
The part im struggling with is getting the content from the div to the server-side. For instance if i used a textarea i would just have my component extends TextArea and that would do all of this for me. So really what im asking is whether there is a wicket component that i can add as a <div wicket:id="mycomponent"></div> but onsubmit populate the component's Model with the content of the div from the client-side. Or do I have to write all this code myself?
You can try adding a normal "wicket" textarea to your form (with display: none) and add a jQuery handler for the form's submit event that will do something like:
$('your-text-area-selector').html($('your-wysiwyg-div-selector').html());

Wicket Table css not rendered after ajax update?

I have a datatable with some items. The datatable has some css on the table tag. When I update the dataproviders model list and send the component back with ajax the css doesn't get rendered.
However if I send the entire page using ajax the table is rendered correct.
Example:
<wicket:panel>
<table class="striped">
</table>
</wicket:panel>
This css class gives odd and even a different css.
This is how I update the component after changing the dataprovider.
ajaxRequestTarget.add(MyPage.this.get("myPanel")); //this panel contains the table
The data gets added but the css markup is gone.
Refreshing the page brings back the css.
ajaxRequestTarget.add(MyPage.this); //send the entire page
This works but the entire page gets refreshed(and this make the page scroll up.
Whats the difference in component rendering if you send the entire page, instead of only 1 component/panel?
I'm using chrome.
If you render styles via jQuery, you'll have to call it again to re-paint correctly.
ajaxRequestTarget.appendJavascript("renderMethod('.striped');");

How to build a URL in the JSF page?

I'm trying to create a <a> tag in my Facelets XHTML page, but can't understand how to do it.. This is what I'm doing:
<h:outputLink value="static/faq.xhtml">FAQ</h:outputLink>
Am I using the right tag?
This should work. Open page in webbrowser, rightclick and View Source to see the JSF-generated HTML output. You should see a <a> element being generated.
To learn what HTML the JSF components are rendering, head to the tag documentation. Here's a cite of relevance of the one for <h:outputLink>:
Render an HTML "a" anchor element. The value of the component is rendered as the value of the "href" attribute.
Simply use FAQ.

Categories

Resources