wicket:link and pages with #AuthorizeInstantiation - wicket

I have a navigation bar like:
<nav>
<ul>
<wicket:link>
<li>Page1</li>
<li>Page2</li>
<li>Page3</li>
</wicket:link>
</ul>
</nav>
This panel works really well (with the matching css).
But, Page3 is only accessible for users logged in.
#AuthorizeInstantiation("SIGNED_IN")
public class Page3 extends MyPage {
// ...
}
When a user is logged in, everything is as expected.
Navigation: Page1 Page2 Page3
But when the user is not logged in, I expect Page3 not to be part of the navigation bar (because it is not accessible).
Navigation: Page1 Page2
How can I do this? TIA!

Add your links using wicket. Then use IAuthorizationStrategy to check if you can instantiate the page the link refers to. Hide the link if not:
IAuthorizationStrategy strategy = getApplication().getSecuritySettings().getAuthorizationStrategy();
Link<?> page1link = new Link<Void>("page1") {
#Override
public void onClick() {
setResponsPage(Page1.class);
}
}
page1link.add(new Label("page1linklabel","Page 1"));
page1link.setVisible(strategy.isInstantiationAuthorized(Page1.class));
add(page1link);
The html for your link then looks like this:
<span wicket:id="page1linklabel"></span>

Related

How to make footer component constant through out the whole site in AEM?

The site structure is as like this in my aem project.
For the footer component i am using following code :-
<div class="ftrsection" data-sly-repeat="${currentPage.listChildren}">
<h3 data-sly-test.child="${item.title}" >${child}</h3>
<ul class="footermenu">
<li data-sly-repeat.subpage="${item.listChildren}">
${subpage.title}
</li>
</ul>
</div>
When i am in the home page it takes it as current page in the first line of the code and displays the site hierarchy in the footer perfectly as this
But when i am in a inner page( here explore page) it takes it as currectPage and displays the footer as this which i dont want . i want it to be constant through out the whole site. How to make it constant?
You can create a Java Use Object (for example Footer.java that allows you to always get the correct root page for your website. You can then invoke it like:
data-sly-use.footer=“Footer” data-sly-repeat=“${footer.rootPage.listChildren}”
It is solved. Had to create a helper class to find the correct root.
File :Footer.java
package com.csmpl.bbsr.me.core.models;
import java.util.*;
import java.util.Iterator;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageFilter;
import com.adobe.cq.sightly.WCMUsePojo;
public class Footer extends WCMUsePojo{
private List<Page> items = new ArrayList<Page>();
private Page rootPage;
// Initializes the navigation
#Override
public void activate() throws Exception {
rootPage = getCurrentPage().getAbsoluteParent(2);
if (rootPage == null) {
rootPage = getCurrentPage();
}
Iterator<Page> childPages = rootPage.listChildren(new PageFilter(getRequest()));
while (childPages.hasNext()) {
items.add(childPages.next());
}
}
// Returns the navigation items
public List<Page> getItems() {
return items;
}
// Returns the navigation root
public Page getRoot() {
return rootPage;
}
}
Then had to access the class in the footer's htl like:
<div class="ftrsection" data-sly-use.footer="com.csmpl.bbsr.me.core.models.Footer" data-sly-repeat="${footer.root.listChildren}">
<h3 data-sly-test.child="${item.title}" >${child}</h3>
<ul class="footermenu">
<li data-sly-repeat.subpage="${item.listChildren}">
${subpage.title}
</li>
</ul>
</div>
And it worked. Hope it helps. :)

ionic 3 from tabbed page to normal page

Pages structure is: Tabs(page1,page2,page3).
When I click a button within in page1, I want to go to page4,
but now we still can see tab, how to make page4 displays as a normal page and can back to tabbed page.
In page1, I use below line to go to page4
this.navCtrl.push(page4);
I think you could first try the following, which is for test only to understand
that this is achievable:
pass params to the ion-tabs like this:
<ion-tabs>
<ion-tab [root]="tabMap" [rootParams]="tabParams" tabIcon="map"></ion-tab>
<ion-tab [root]="tabList" [rootParams]="tabParams" tabIcon="list"></ion-tab>
</ion-tabs>
Prepare the params in the tabs.ts like this:
ionViewWillEnter() {
this.tabParams.parentNav = this.navCtrl;
}
So in the inner page (page1, 2, 3) you can retrieve it, place it in a variable e.g. parentNav, and when you want to navigate out of the tabs page to do a this.parentNav.push(page4).
The proper way I think is to use events events: ionic forum
So in the tabs.ts page you could have this piece of code:
events.subscribe('tabs:newPage', (page) => {
this.navCtrl.push(page);
});
And in each page, or in a service you could have:
newPage(page) {
console.log('navigate to a new page, not a tab')
this.events.publish('tabs:newPage', page);
}
What ionic is ?
If lazy loading,maybe ionic 3 , hod did you declare page4?
You have to push it like this : this.navCtr.push('page4');
If is all ok try this (it 's extracted form an app example) :
static get parameters() {
return [[IonicApp], [NavController], [ConferenceData], [UserData]];
}
constructor(app, nav, ...) {
// all of the constructor code
}
tourFunction() {
let nav = this.app.getComponent('nav');
nav.push('page4');
}
Ref

How to navigate between screens in react native with separeate js files

I have react native project and I saved the home screen and details screens as oneScreen.js and two screen.js inside the src directory but there class names are different. So now I want call to them from App.js file and after a button press in home screen it should directed to details screen.how to do this using createStack navigator.
Can you try with bellow command. I am not sure it works on your structure. You should provide more screenshoot.
<Button
...
onPress = {() => this.props.navigation.navigate("ScreenName")}
/>
in App.js
import Homescreen from './onescreen';
import Detailscreen from './twoscreen';
class Homescreen extends component{
static navigationoptions={
enter code here
};
render(){
return(
<Homescreen navigation={this.props.navigation} />
);
}
}
class Detailsscreen extends component{
static navigationOptions={
enter code here
}
render(){
return(
<Detailsscreen navigation={this.props.navigation}/>
);
}
}
export default App = createStackNavigator(
{
Home:{screen:Homescreen},
Details:{screen:Detailsscn}
}
);
//you can put additional properties inside the navigationOptions
in buttonPress you can call
this.props.navigation.navigate('Home'); to navigate home
this.props.navigation.navigate('Details'); to navigate Details

Ionic2: use getActive() to change button color for the active page

I have a nav component which I am using on 4 pages, I want to be able to change the color of active page's button in the nav component. In Ionic app doc's for nav controller I found getActive() instance, but I can't figure out how to achieve the desired result with it. I'm using the following code to push to a new view.
viewPage2(){
this.navCtrl.push(Page2);
}
<button ion-button (click)="viewPage2()" color="dark" clear full>Page 2</button>
NavController getActive() returns the ViewController of the Active page.
Looking at the API of ViewController you could try using getContentRef():
this.navCtrl.getActive().contentRef().nativeElement.getElementById("button_id")
Once you have the element you could change the color.
Even though getting the html element by its id may work, modifying the DOM directly is not the recommended way to do things in Ionic.
First option:
If that's a custom component, you can always expose a public method in that component, and get the reference by using ViewChild
#Component({...})
export class NavCustomComponent {
public activePage: string = 'page1';
//...
public changeActivePage(pageName: string): void {
this.activePage = pageName;
}
// ...
}
And in your view:
<button ion-button (click)="viewPage2()" [color]="activePage === 'page2' ? 'light' : 'dark'" clear full>Page 2</button>
Then in the page where you're trying to modify the component:
#Component({...})
export class DemoPage {
#ViewChild(NavCustomComponent) navCustomComponent: NavCustomComponent;
}
and then use that reference to call that public method:
this.navCustomComponent.changeActivePage('page2');
Second option:
If that's not a custom component, or you just want to make things even simpler, you can just Events. Whereever you're defining the code of that nav component, (or in your app.component.ts file to make it global for the entire app) subscribe to the event:
public activePage: string = 'page1';
constructor(public events: Events, ...) {
events.subscribe('page:selected', (pageName) => {
this.activePage = pageName;
});
}
Again, in your view:
<button ion-button (click)="viewPage2()" [color]="activePage === 'page2' ? 'light' : 'dark'" clear full>Page 2</button>
And then in the component where you want to change the color, just publish that event:
events.publish('page:selected', 'page2');

Redirect Vaadin App

I am currently hosting my vaadin app on openshift. My main website redirects to the vaadin app when the login button is clicked. The first thing the user sees is the login page
I have 2 buttons on my website, a free trial button and a login button, and I have 2 different classes in my vaadin app, a login class and a free trial class.
How can I make the login button redirect to the login class of my vaadin app and the free trial button redirect to the free trial class of my vaadin app?
This is what it currently looks like:
#Theme("mytheme")
#Widgetset("com.example.myapp.MyAppWidgetset")
#PreserveOnRefresh
public class MyUI extends UI {
#WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest vaadinRequest) {
login();
}
You can use the Navigator as Chris M said, or you can try to implement an event driven architecture. I implemented a project like that using Vaadin too with Google Guava.
Here you can find some examples of how to use Google Guava if you are interested.
http://codingjunkie.net/guava-eventbus/
Below you can find some code fragments of my implementation:
// Using guava
final Button signin = new Button(
Lang.getMessage("login.signin"),
eventClick -> {BarsEventBus.post(new UserLoginRequestedEvent(
username.getValue(), password.getValue()));});
//Using Navigator, I also used spring here, so the registration view is a Spring View
final Button register = new Button(
Lang.getMessage("login.registration"),
clickEvent -> {getUI().getNavigator().navigateTo(ViewToken.REGISTRO);}
);
#UIScope
#SpringView(name = ViewToken.REGISTRO)
public class RegistrationView extends VerticalLayout implements View {...}
Please verify the code for the vaadin demo application. That code is having an example on how to handle it too. Find it here:
https://github.com/vaadin/dashboard-demo
You could pass in a parameter to your request and use a UI provider to serve the UI depending on this parameter.
See here.
Example:
public class DifferentFeaturesForDifferentClients extends UIProvider {
#Override
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
if ("trial".equalsIgnoreCase(event.getRequest().getParameter("app-type"))) {
return TrialUI.class;
} else {
return LognUI.class;
}
}
}
web.xml:
<servlet>
<servlet-name>My Vaadin App</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<description>Vaadin UI</description>
<param-name>UIProvider</param-name>
<param-value>com.example.myexampleproject.DifferentFeaturesForDifferentClients</param-value>
</init-param>
</servlet>
And then in your main websites html code:
<form>
<input type="submit" name="app-type" value="Trial" formaction="/your/vaadin/url" formmethod="post">
<input type="submit" name="app-type" value="Login" formaction="/your/vaadin/url" formmethod="post">
<!-- Alternative using button tag (better for customization, but no IE < 9) -->
<button name="app-type" value="trial" type="submit">Trial</button>
<button name="app-type" value="login" type="submit">Login</button>
</form>
I now understand what you were truing to do. You can do this quite easily. You need to cast the VaadinRequest into a VaadinServletRequest. The reason it passes a VaadinRequest rather than an VaadinServletRequest is so you can deploy your application as a portlet too. In that case you would need to cast it to VaadinPortletRequest instead. Then you can use the serverName provided by the user.
#Override
protected void init(VaadinRequest vaadinRequest) {
VaadinServletRequest req = (VaadinServletRequest) vaadinRequest;
String serverName = req.getServerName();
if (serverName.equals("www.login.mywebsite.com"))
{
login();
}
else
{
trial();
}
}